#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<unordered_map>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef int LL;
template<class T>inline void read(T &res)
{
    char c;T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;read(n);
  LL sum=0;LL lastnum=0;
  for(LL i=1;i<=n;i++){
    LL x;read(x);
    if(sum==0){
        lastnum=x;
    }
    else{
        sum--;
    }
  }
  printf("%d\n",lastnum);
return 0;
}
